<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>报单系统</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../Public/css/Home/mui.css" />
		<link rel="stylesheet" href="../Public/css/Home/public.css" />
		<link rel="stylesheet" href="../Public/css/Home/login.css" />
	</head>

	<body class="bg-white">
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">手机快速注册</h1>
		</header>
		<div class="mui-content bg-white">
			<form class="login">
				<ul>
					<li class="layout-center">
						<div class="flex-item1">
							<input type="number" name="code" id="code" placeholder="请输入手机验证码" oninput="highliht(this);" onkeydown="highliht(this);" onkeyup="highliht(this);" >
						</div>
						<span id="getCode" class="btn-vcode2">获取验证码</span>
					</li>
				</ul>
				<div class="btn-box2">
					<a href="javascript:void(0);" id="nextStep" class="btn next-step disabled">下一步</a>
					<div class="agreement-box">点击完成即代表您同意 <a href="javascript:void(0);" class="agreement">注册协议</a></div>
				</div>
			</form>
		</div>
	</body>
	<script src="../Public/js/Home/jquery.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../Public/js/Home/mui.js" type="text/javascript" charset="utf-8"></script>
	<script src="../Public/js/Home/common.js" type="text/javascript" charset="utf-8"></script>
	<script>
		var user_name,trueCode;
		var getCodeBtn = document.getElementById("getCode");
		
		mui.init();
		
		$(function(){
			
			user_name = common.getLocVal("reg_user_name");
		});
		
		//请求发送验证码
		getCodeBtn.addEventListener('tap', getCode);

		function getCode() {
			getCodeBtn.removeEventListener('tap', getCode);
			var params = {
				url: "Identify/getEmsCode",
				data: {
					mobile: user_name,
					type: 0
				}
			};
			common.JsonPost(params, function(data) {
				console.log('获取短信验证码' + JSON.stringify(data));
				trueCode = data;
				
				window.elapseTmpInterval = window.setInterval(function() {
					if(window.elapsedCounter === undefined) {
						window.elapsedCounter = 120;
					}
					if(window.elapsedCounter < 1) {
						window.clearInterval(window.elapseTmpInterval);
						window.elapsedCounter = 120;
						getCodeBtn.addEventListener('tap', getCode);
						getCodeBtn.innerHTML = "重新发送";
						return;
					}
					getCodeBtn.innerHTML = "重新发送(" + window.elapsedCounter + "s)";
					window.elapsedCounter--;
				}, 1000)
			})
		}
		
		//按钮是否可点
		function highliht(dom) {
			if(dom.value.length > 0 ){
				document.getElementById("nextStep").classList.remove("disabled");
				document.getElementById("nextStep").addEventListener('tap', send);
			}else{
				document.getElementById("nextStep").classList.add("disabled");
			}
		}
		
		function send() {
			var ems_code = document.getElementById("code").value;
			if(!ems_code) {
				common.alert("提示", "请输入验证码");
				return false;
			}
                        
                        common.setLocVal("reg_ems_code",ems_code);
                        common.setLocVal("reg_send_ems_code",trueCode);
			mui.openWindow({
				url: "reg_three.html",
				id: "reg_three",
				extras: {
					user_name: user_name,
					ems_code: ems_code,
					send_ems_code: trueCode
				}
			})
		}
		
	</script>

</html>